<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
			
	billCd		= Request("billCd")
	fullLotNo	= Request("fullLotNo")
	lotSubNo	= Request("lotSubNo")
	rank			= Request("rank")
	prdNm		= Request("prdNm")
	goodQty	= Request("goodQty")
	unitPrice	= Request("unitPrice")
	totalPrice	= Request("totalPrice")
	orderNo	= Request("orderNo")
	orderPrdCd	= Request("orderPrdCd")
	compCd	= Request("compCd")
	flag			= Request("flag")

	If unitPrice = "" Then unitPrice = "0" End If 
	If goodQty = "" Then goodQty = "0" End If 
	If totalPrice = "" Then totalPrice = "0" End If 
	If rank = "" Then rank = "0" End If 
	If compCd = "" Then compCd = "0" End If 
	
	prdNm				= Replace(prdNm,"'","''")
	unitPrice			= Replace(unitPrice,",","")
	goodQty			= Replace(goodQty,",","")
	totalPrice			= Replace(totalPrice,",","")
	
	issueId = Request.Cookies("S_uid")
		
	SQLTitle = "-- ■■■■ 거래명세서 품목 정보 관리 저장 ■■■■"
	if lotSubNo = "" then	
		lotYear = right(left(date(),4),2)
		lotNo = "9999"
		rank = 1
		lotSubNo = aFieldValue("SELECT ISNULL(MAX(lotSubNo),0)+1 FROM tblBizBill WHERE lotYear='" & lotYear & "' AND lotNo='" & lotNo & "' AND billCd=" & billCd & " AND rank=" & rank)
		SQL = "INSERT INTO tblBizBill (billCd, lotYear, lotNo, lotSubNo, rank, compCd, prdNm, unitPrice, goodQty, totalPrice, orderNo, orderPrdCd, addDt, addUserId) " & _
				" VALUES(" & billCd & ", '" & lotYear & "', '" & lotNo & "', " & lotSubNo & ", " & rank & ", " & compCd & ", '" & prdNm & "', " & unitPrice & ", " & goodQty & ", " & totalPrice & ", '" & orderNo & "', '" & orderPrdCd & "', getdate(), '" & issueId & "') "
        'Response.write sql				
	else
		SQL = "UPDATE tblBizBill SET prdNm='" & prdNm & "', goodQty=" & goodQty & ", unitPrice=" & unitPrice & ", totalPrice=" & totalPrice & ", orderNo='" & orderNo & "', orderPrdCd='" & orderPrdCd & "', flag='" & flag & "', updateUserId='" & issueId & "', updateDt=getdate() " & _
				"	WHERE lotYear+lotNo='" & fullLotNo & "' AND lotSubNo=" & lotSubNo & " AND billCd=" & billCd & " AND rank=" & rank
	end if 
	
	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

'Response.write SQL
'Response.end
	DbCon.Execute SQL

	Call rsWithXML("Save OK!")
%>